package com.loong.seller.controller.backend;

import com.loong.common.domain.BaseQuery;
import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.seller.common.backend.param.ShopTypeParam;
import com.loong.seller.common.backend.param.ShopTypeQueryParam;
import com.loong.seller.handler.ShopTypeHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 店铺类型控制器
 * @Author: hzp
 * @Date: 2020-12-3 9:22
 */
@RestController
@RequestMapping("/manage/seller/shopType")
public class ShopTypeController extends BaseBackendController {

    @Resource
    private ShopTypeHandler shopTypeHandler;

    /**
     * 保存店铺类型
     * @param param 店铺类型
     * @return 200
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) ShopTypeParam param){
        param.setId(null);
        return handlerExecutor.execute(()->shopTypeHandler.save(param));
    }


    /**
     * 更新店铺类型
     * @param param 店铺类型
     * @return 200
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) ShopTypeParam param){
        return  handlerExecutor.execute(()->shopTypeHandler.update(param));
    }

    /**
     *根据id删除店铺类型
     * @param id 店铺类型id
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("id") Long id){
        return handlerExecutor.execute(()->shopTypeHandler.deleteById(id));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("batchDelete")
    public Result batchDeleteByIds(@RequestParam("ids") List<Long> ids){
        return handlerExecutor.execute(()->shopTypeHandler.batchDelete(ids));
    }


    /**
     * 根据店铺类型id查找店铺类型
     * @param id
     * @return
     */
    @PostMapping("view")
    public Result findShopByShopId(@RequestParam("id") Long id){
        return handlerExecutor.execute(()->shopTypeHandler.findShopTypeById(id));
    }


    /**
     * 分页查询
     * @param baseQuery 分页对象
     * @param param 查询条件
     * @return 店铺分页结果集
     */
    @PostMapping("pageQuery")
    public Result pageQuery(BaseQuery baseQuery, ShopTypeQueryParam param){

        return  handlerExecutor.execute(()->shopTypeHandler.pageQuery(baseQuery,param));
    }

}
